﻿using System;
using System.Collections.Generic;
using System.Text;
using BBMS.DAL.IDAL;
using BBMS.FrontEnd.Constant;
using BBMS.BLL.DataContract;

namespace BBMS.BLL.Implementation
{
    public class DALclient
    {
        IParam dalParam;
        IBank dalBank;

        #region IParam Members

        public void insertParm(ParamData item)
        {
            dalParam = BBMS.DAL.Factory.ParamFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalParam.Open(ConfigFromDb.MySQLCNN);
                dalParam.insertParm(item);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalParam.Close();
            }
        }

        public List<ParamData> getAllParam()
        {
            dalParam = BBMS.DAL.Factory.ParamFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalParam.Open(ConfigFromDb.MySQLCNN);
                return dalParam.getAllParam();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalParam.Close();
            }
        }

        public ParamData getParamByCode(string code)
        {
            dalParam = BBMS.DAL.Factory.ParamFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalParam.Open(ConfigFromDb.MySQLCNN);
                return dalParam.getParamByCode(code);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalParam.Close();
            }
        }

        public ParamData getParamByName(string name)
        {
            dalParam = BBMS.DAL.Factory.ParamFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalParam.Open(ConfigFromDb.MySQLCNN);
                return dalParam.getParamByName(name);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalParam.Close();
            }
        }

        #endregion

        #region IBank Members

        public void insertBank(BankData item, string provider)
        {
            dalBank = BBMS.DAL.Factory.BankFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalBank.Open(ConfigFromDb.MySQLCNN);
                dalBank.insertBank(item, provider);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalBank.Close();
            }
        }

        public void deleteBank(string code)
        {
            throw new NotImplementedException();
        }

        public void deleteBankByProvider(string provider)
        {
            dalBank = BBMS.DAL.Factory.BankFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalBank.Open(ConfigFromDb.MySQLCNN);
                dalBank.deleteBankByProvider(provider);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalBank.Close();
            }
        }

        public List<BankData> getAllBank()
        {
            throw new NotImplementedException();
        }

        public List<BankData> getBankByProvider(string provider)
        {
            dalBank = BBMS.DAL.Factory.BankFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalBank.Open(ConfigFromDb.MySQLCNN);
                return dalBank.getBankByProvider(provider);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalBank.Close();
            }
        }

        public BankData getBankByCode(string code)
        {
            dalBank = BBMS.DAL.Factory.BankFactory.Create(ConfigFromFile.DBType);
            try
            {
                dalBank.Open(ConfigFromDb.MySQLCNN);
                return dalBank.getBankByCode(code);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalBank.Close();
            }
        }

        public BankData getBankByName(string name)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
